﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Habanero.Faces.Win;

namespace Firestarter.DB.Schema.UI
{
    public class PictureButton : ButtonWin
    {


        Image _pressedImage;
        Image _buttonImage;
        Image _hoverImage;
        bool _isPressed;
        bool _isOver;

        public PictureButton()
        {
            Button button = new Button();
            button.Font = DefaultFont;
            FlatAppearance.BorderSize = 0;
            FlatAppearance.MouseDownBackColor = Color.Transparent;
            FlatAppearance.MouseOverBackColor = Color.Transparent;
            FlatStyle = FlatStyle.Flat;
            //TextAlign = ContentAlignment.MiddleCenter;
            //Font = new Font("Tahoma", 8, FontStyle.Regular, GraphicsUnit.Point, 0);
            //BackgroundImageLayout = ImageLayout.Stretch;
            //Size = AssetMgmtUtilities.SmallButtonSize;
            //ForeColor = Color.Black;
            //BackgroundImage = ImageResources.GetImage("blank.png");
            //ButtonImage = ImageResources.GetImage("defaultbutton.png");
            //HoverImage = ImageResources.GetImage("hoverbutton.png");
            //PressedImage = ImageResources.GetImage("pressedbutton.png");
        }

        public Image PressedImage
        {
            get
            {
                return this._pressedImage;
            }
            set
            {
                this._pressedImage = value;
                UpdateBackgroundImage();
            }
        }

        public Image ButtonImage
        {
            get
            {
                return this._buttonImage;
            }
            set
            {
                this._buttonImage = value;
                UpdateBackgroundImage();
            }
        }

        public Image HoverImage
        {
            get
            {
                return this._hoverImage;
            }
            set
            {
                this._hoverImage = value;
                UpdateBackgroundImage();
            }
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (!_isPressed)
            {
                _isPressed = true;
                UpdateBackgroundImage();
            }
            base.OnMouseDown(e);
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (_isPressed)
            {
                _isPressed = false;
                UpdateBackgroundImage();
            }
            base.OnMouseUp(e);
        }

        private void UpdateBackgroundImage()
        {
            if (_isPressed)
            {
                BackgroundImage = _pressedImage;
                ForeColor = Color.Black;
            }
            else if (_isOver)
            {
                BackgroundImage = _hoverImage;
                ForeColor = Color.White;
            }
            else
            {
                BackgroundImage = _buttonImage;
                ForeColor = Color.Black;
            }
        }

        protected override void OnMouseEnter(EventArgs e)
        {
            if (!_isOver)
            {
                _isOver = true;
                UpdateBackgroundImage();
            }
            base.OnMouseEnter(e);
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            if (_isOver)
            {
                _isOver = false;
                UpdateBackgroundImage();
            }
            base.OnMouseLeave(e);
        }


    }
}
